#
# Copyright (C) 2015-2020 wm@wmdevice.com
#
# WMD Property Software.
#

include $(TOPDIR)/rules.mk

# 包名称
PROJECT_ID:=lay

PKG_NAME:=${PROJECT_ID}
export PROJECT_ID
# Makefile版本号
PKG_RELEASE:=1
# 包版本号
VERSION_ID := 6.0.0
PKG_VERSION:=${VERSION_ID}
export VERSION_ID
# 包编译时的目录
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk
sinclude ${gMAKEFILE_LIBFILE}

# menuconfig的选项的位置及说明
define Package/$(PKG_NAME)
  CATEGORY:=Farm system
  TITLE:=Platform lay support
  DEPENDS:=+land +network +librt +libevent2 +libopenssl
endef
# menuconfig的界面上的帮助
define Package/$(PKG_NAME)/description
  Platform lay support
endef

# 编译前准备工作, 通常可能会copy到PKG_BUILD_DIR中去编译, 我们将在本地编译
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	if [ -d ${gPLATFORM_DIR}/lay ]; then \
		tmpls=`find ${gPLATFORM_DIR}/lay -maxdepth 1 -name "*.fpk"`; \
		if [ "X$$$${tmpls}" != "X" ]; then \
			$(CP) ${gPLATFORM_DIR}/lay/*.fpk $(PKG_BUILD_DIR); \
		fi \
	fi
	if [ -d ${gHARDWARE_DIR} ]; then \
		tmpls=`find ${gHARDWARE_DIR} -maxdepth 1 -name "*.fpk"`; \
		if [ "X$$$${tmpls}" != "X" ]; then \
			$(CP) ${gHARDWARE_DIR}/*.fpk $(PKG_BUILD_DIR); \
		fi \
	fi
	if [ -d ${gCUSTOM_DIR} ]; then \
		tmpls=`find ${gCUSTOM_DIR} -maxdepth 1 -name "*.fpk"`; \
		if [ "X$$$${tmpls}" != "X" ]; then \
			$(CP) ${gCUSTOM_DIR}/*.fpk $(PKG_BUILD_DIR); \
		fi \
	fi
	if [ -d ${gSCOPE_DIR} ]; then \
		tmpls=`find ${gSCOPE_DIR} -maxdepth 1 -name "*.fpk"`; \
		if [ "X$$$${tmpls}" != "X" ]; then \
			$(CP) ${gSCOPE_DIR}/*.fpk $(PKG_BUILD_DIR); \
		fi \
	fi
endef
# 编译
define Build/Compile
	if [ -d ${gPLATFORM_DIR}/arch ]; then \
		rm -fr $(PKG_BUILD_DIR)/arch-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/land ]; then \
		rm -fr $(PKG_BUILD_DIR)/land-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/network ]; then \
		rm -fr $(PKG_BUILD_DIR)/network-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/client ]; then \
		rm -fr $(PKG_BUILD_DIR)/client-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/wui ]; then \
		rm -fr $(PKG_BUILD_DIR)/wui-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/agent ]; then \
		rm -fr $(PKG_BUILD_DIR)/agent-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/controller ]; then \
		rm -fr $(PKG_BUILD_DIR)/controller-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/uart ]; then \
		rm -fr $(PKG_BUILD_DIR)/uart-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/vpn ]; then \
		rm -fr $(PKG_BUILD_DIR)/vpn-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/ipsec ]; then \
		rm -fr $(PKG_BUILD_DIR)/ipsec-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/ha ]; then \
		rm -fr $(PKG_BUILD_DIR)/ha-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/sslvpn ]; then \
		rm -fr $(PKG_BUILD_DIR)/sslvpn-*.fpk; \
	fi
	if [ -d ${gPROJECT_DIR}/gnss ]; then \
		rm -fr $(PKG_BUILD_DIR)/gnss-*.fpk; \
	fi
	if [ -d ${gSDK_DIR}/package/kernel/fdriver ]; then \
		rm -fr $(PKG_BUILD_DIR)/farm-driver.fpk; \
	fi
endef

# 安装到系统运行目录中( 注意必须要有这个函数才会执行Build/Compile )
define Package/$(PKG_NAME)/install
	for c in $(PKG_BUILD_DIR)/*.fpk; do \
		if [ -f $$$$c ]; then \
			fpk-install ${1} ${gTOP_DIR}/noexist $$$$c; \
			fpk-install ${gosROOT_DIR} ${gINSTALL_DIR} $$$$c; \
		fi; \
	done
endef

# 调用编译安装
$(eval $(call BuildPackage,$(PKG_NAME)))

